﻿#ifndef PROTOCOLPARSE_H
#define PROTOCOLPARSE_H
#include "oscbb.h"
#include <QString>
#include "json.h"
#include "JsonCheck.h"
#include "common.h"


#ifdef __cplusplus
extern "C" {
#endif

//"ui_type":"[all/interval/arrive/welcome/emergency/...]",
//"file_path":"all_1_1.xml",
//"start_id":"1",
//"stop_id":"20",
//"curr_id":"3",
//"next_id":"4",
//"car_number":"1",
//"door_status":"1",
//"skip_list":[1,2,3,6],
//"eta_list":[20,50,67,123,222,467],
//"scroll_msg":"Hello world",
//"emergency_img":"1.png",
//"texts":[{"id":"title","text":"Hello"},{"id":"cn","text":"你好，世界"},{"id":"en","text":"Hello World"}]

class ProtocolParse
{
public:

/// 发送函数回调
    typedef int (*FSendBufCb)(void *context, void *link, void *buf, int len, uint32_t ip, uint16_t port, uint64_t time);

    typedef void (*FShowXml)(void *context, QString);//

    static void *routine(void *arg);

    ProtocolParse();

    int create(QString);

    /// 设置发送回调,本项目暂时用不到
    void set_send_data_cb(FSendBufCb snd_buf_cb, void *snd_buf_ctx);

    void set_parse_file_cb(FShowXml, void *);

    /// data income from link
    void data_in(void *buf, int buf_len, uint32_t ip, uint16_t port, uint64_t cur_time);

    /// data income from link
    void data_in_from_unix(void *buf, int buf_len, uint64_t cur_time, ProtocolData*);

    int send_data(void *context, void *buf, int buf_len, uint32_t ip, uint16_t port);

    void set_protocol(int ptl);
private:
    /// parse data from link
    void parse_data(void *buf, int len, ProtocolData*);


private:
    FSendBufCb  snd_buf_cb;
    void        *snd_buf_cb_ctx;

    FShowXml    show_cb;
    void        *show_cb_context;

    uint32_t    rmt_ip;
    uint16_t    rmt_port;
    uint64_t    cur_time;
    int         protocol;

//    QString     m_img_path;
//    QString     m_xml_path;

    QString     m_res_path;
};

#ifdef __cplusplus
}
#endif

#endif // PROTOCOLPARSE_H
